<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>统计出现最多的字符</title>
</head>
<body>
    
</body>
<script>
    let str = "sdfksdjfiowetrjaslfadsfasdgw4r";

    // 切割成单个字符串
    // 临时变量统计次数
    // 逐一比较
    function findMax(str) {
        if (str.length == 1) {
            return str
        }

        let charObj = {}
        for (let i = 0; i < str.length; i++) {
            !charObj[str.charAt(i)] ? charObj[str.charAt(i)] = 1 : charObj[str.charAt(i)] += 1;
        }

        let maxStr = '', maxValue = 1;
        console.log(charObj);

        for (let k in charObj) {
            if (charObj[k] >= maxValue) {
                maxStr = k
                maxValue = charObj[k]
            }
        }
        return maxStr
    }

    console.log(findMax(str))


</script>
</html>